<!doctype html>
<html>
    <head>
        <!-- meta -->
        <!-- meta -->
        <title>Events</title>
        <!-- css -->
        <link href="../styles/examples.css" rel="stylesheet"/>
        <link href="../../source/styles/kendo.common.css" rel="stylesheet"/>
        <link href="../../source/styles/kendo.kendo.css" rel="stylesheet"/>
        <!-- css -->
        <!-- script -->
        <script src="../js/jquery.js"></script>
        <script src="../../source/js/kendo.core.js"></script>
        <script src="../../source/js/kendo.upload.js"></script>
        <!-- script -->
    </head>
    <body>
        <!-- nav -->
        <!-- nav -->
        <!-- description -->
        <!-- description -->
        <div id="example" class="k-content">
            <div class="configuration">
                <span class="infoHead">Information</span>
                <p>
                    This example shows how to handle events triggered by kendoUpload.
                </p>
                <p>
                    <strong>Note:</strong>
                    Security restrictions in Chrome prevent this
                    example from working when the page is
                    loaded from the file system (via file:// protocol).
                </p>
            </div>
            <div style="width:60%">
                <input name="files" id="files" type="file" />
            </div>
            <script>
                function onSelect(e) {
                    kendoConsole.log("Select :: " + getFileInfo(e));
                }

                function onUpload(e) {
                    kendoConsole.log("Upload :: " + getFileInfo(e));
                }

                function onSuccess(e) {
                    kendoConsole.log("Success (" + e.operation + ") :: " + getFileInfo(e));
                }

                function onError(e) {
                    kendoConsole.log("Error (" + e.operation + ") :: " + getFileInfo(e));
                    e.preventDefault(); // Suppress error message
                }

                function onComplete(e) {
                    kendoConsole.log("Complete");
                }

                function onCancel(e) {
                    kendoConsole.log("Cancel :: " + getFileInfo(e));
                }

                function onRemove(e) {
                    kendoConsole.log("Remove :: " + getFileInfo(e));
                }

                function getFileInfo(e) {
                    return $.map(e.files, function(file) {
                        var info = file.name;

                        // File size is not available in all browsers
                        if (file.size > 0) {
                            info  += " (" + Math.ceil(file.size / 1024) + " KB)";
                        }
                        return info;
                    }).join(", ");
                }

                $(document).ready(function() {
                    $("#files").kendoUpload({
                        async: {
                            saveUrl: "blank.html",
                            removeUrl: "blank.html",
                            autoUpload: true
                        },
                        select: onSelect,
                        upload: onUpload,
                        success: onSuccess,
                        error: onError,
                        complete: onComplete,
                        cancel: onCancel,
                        remove: onRemove
                    });
                });
            </script>
        </div>
        <div class="console"></div>
        <!-- tools -->
        <!-- tools -->
    </body>
</html>

